import addDamFluid from "../../rehearsal/damFluid";
export default class Effect4 {
  constructor(viewer){
    this.viewer = viewer

    this.fluidRendering = addDamFluid(viewer)

    this.start()
  }

  start(){
    this.viewer.scene.globe.terrainExaggeration = 0.7;    
    this.viewer.camera.flyTo({
      destination: Cesium.Cartesian3.fromDegrees(113.10253207818093, 27.731695495527322, 1556.5261513434336), //设置位置
      orientation: {
        heading: Cesium.Math.toRadians(70.54310942599443),
        pitch: Cesium.Math.toRadians(-36.58914391978159),
        roll: 0
      }
    });
    setTimeout(() => {
      this.startWater()
    }, 3000);

  }

  //开始泄洪
  startWater(){

    let range = 0.005;
    let depth = 0.013;

    this.fluidRendering.getHeightMap()
      //6个泄洪口
      var p1 = Cesium.Cartesian3.fromDegrees(113.12232200230504,27.73921854559983);
      var p2 = Cesium.Cartesian3.fromDegrees(113.122237,27.739178,3.205796494937708);
      var p3 = Cesium.Cartesian3.fromDegrees(113.122348,27.738985,3.5701688044320594);


      var list = [p1];
      var index = 0;
      //每帧加三个泄洪口，一次加6个泄洪口会导致前三个泄洪口无效不出水
      var count = 1;
      
      this.viewer.scene.postRender.addEventListener(()=>{
          if (this.viewer.scene._frameState.frameNumber % 1 == 0) {
              for (var j = 0; j < count; j++) {
                  index++;
                  if (index == list.length) {
                      index = 0;
                  }
                  this.fluidRendering.addWater(list[index], range, depth);
              }
          }
      });
  }
  
    //清除溃堤
    removeWater(){
      this.fluidRendering && this.viewer.scene.primitives.remove(this.fluidRendering)
    }

  clear(){
    this.viewer.scene.globe.terrainExaggeration = 0.01;
    this.removeWater()
  }

}